/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package model.DAO;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
import model.entities.Room;
import model.entities.RoomStatus;
import model.entities.RoomType;

/**
 *
 * @author Hieu.Nguyen
 */
public class RoomTypeDAO {
    private static RoomTypeDAO roomTypeDAO;

    public static RoomTypeDAO getInstance() {
        if (roomTypeDAO == null) {
            roomTypeDAO = new RoomTypeDAO();
        }
        return roomTypeDAO;
    }
    
     public List<RoomType> getRoomType(boolean isActived) {
        List<RoomType> listRoomType = new ArrayList<RoomType>();
        try {
            Connection conn = ConnectionFactory.getConnection();
            String sql = "select * from tblRoomType";
            PreparedStatement pstmt = conn.prepareStatement(sql);
            
            ResultSet rs = pstmt.executeQuery();
            while (rs.next()) {
                RoomType r = new RoomType();
                r.setRoomTypeID(rs.getInt("RoomTypeID"));
                r.setRoomType(rs.getString("RoomType"));
                r.setRoomDecs(rs.getBoolean("RoomDesc"));
                r.setRoomRate(rs.getInt("RoomRate"));
                r.setNumBeds(rs.getInt("NumBeds"));
                r.setGiaPhong(rs.getFloat("GiaPhong"));
                listRoomType.add(r);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return listRoomType;
    }
     public RoomType getRoomTypeByID(int roomTypeID) {

        RoomType rt = new RoomType();
        try {
            Connection conn = ConnectionFactory.getConnection();
            String sql = "select * from tblRoomType where RoomTypeID = ? ";
            PreparedStatement pstmt = conn.prepareStatement(sql);
            pstmt.setInt(1, roomTypeID);
            
            ResultSet rs = pstmt.executeQuery();
            while (rs.next()) {                
                rt.setRoomTypeID(rs.getInt("RoomTypeID"));
                rt.setRoomType(rs.getString("RoomType"));
                rt.setRoomDecs(rs.getBoolean("RoomDesc"));
                rt.setRoomRate(rs.getInt("RoomRate"));
                rt.setNumBeds(rs.getInt("NumBeds"));
                rt.setGiaPhong(rs.getFloat("GiaPhong"));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        return rt;
     }
      public RoomType getAllRoomType(boolean desc) {

        RoomType rt = new RoomType();
        try {
            Connection conn = ConnectionFactory.getConnection();
            String sql = "select * from tblRoomType where RoomDesc = ?";
            PreparedStatement pstmt = conn.prepareStatement(sql);
            pstmt.setBoolean(1, desc);
            
            ResultSet rs = pstmt.executeQuery();
            while (rs.next()) {
                
                rt.setRoomTypeID(rs.getInt("RoomTypeID"));
                rt.setRoomType(rs.getString("RoomType"));
                rt.setRoomDecs(rs.getBoolean("RoomDesc"));
                rt.setRoomRate(rs.getInt("RoomRate"));
                rt.setNumBeds(rs.getInt("NumBeds"));
                rt.setGiaPhong(rs.getFloat("GiaPhong"));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        return rt;
     }
       public boolean createRoomType(RoomType roomType) {
        boolean isCheck = false;
        try {
            Connection conn = ConnectionFactory.getConnection();
            String sql = "insert into tblRoomType values (?,?,?,?,?)";
            PreparedStatement pstmt = conn.prepareStatement(sql);
           
            pstmt.setString(1, roomType.getRoomType());
            pstmt.setBoolean(2, roomType.isRoomDecs());
            pstmt.setInt(3, roomType.getRoomRate());
            pstmt.setInt(4, roomType.getNumBeds());
            pstmt.setFloat(5, roomType.getGiaPhong());
            
            
            pstmt.executeUpdate();
            isCheck = true;
        } catch (Exception e) {
            System.out.println(e.toString());
        }
        return isCheck;
     }
}
